package com.itheima.trade.controller;

import com.itheima.model.common.dtos.AccountDto;
import com.itheima.model.common.dtos.ResponseResult;
import com.itheima.trade.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    /**
     * 转账
     * @param accountDtoMap
     * @return
     */
    @PostMapping("/transfer")
    public ResponseResult transfer(@RequestBody Map<String,AccountDto> accountDtoMap){
        AccountDto fromAccount = accountDtoMap.get("fromAccount");
        AccountDto toAccount = accountDtoMap.get("toAccount");
        return accountService.transfer(fromAccount,toAccount);
    }

    /**
     * 存钱
     * @param accountDto
     * @return
     */
    @PostMapping("/saving")
    public ResponseResult saving(@RequestBody AccountDto accountDto){
        return accountService.saving(accountDto);
    }

    /**
     * 取钱
     * @param accountDto
     * @return
     */
    @PostMapping("/withdrawMoney")
    public ResponseResult withdrawMoney(@RequestBody AccountDto accountDto){
        return accountService.withdrawMoney(accountDto);
    }
}
